﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Setup.UC
{
    public partial class SelectPath : UserControl
    {
        public SelectPath()
        {
            InitializeComponent();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (fd.ShowDialog() == DialogResult.OK)
                this.textBox1.Text = fd.SelectedPath;
            if (string.IsNullOrEmpty(this.textBox1.Text))
                this.textBox1.Text = string.IsNullOrEmpty(Logic.Install.InstallLocation) ?
                       "C:\\" + Logic.Install.DisplayName : Logic.Install.InstallLocation;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Logic.MainForm.Up();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string path = textBox1.Text;
            try
            {
                if (!System.IO.Path.IsPathRooted(textBox1.Text))
                    textBox1.Text = "C:\\" + Logic.Install.DisplayName;
                path=System.IO.Path.GetFullPath(textBox1.Text);
                System.IO.Directory.CreateDirectory(path);
            }
            catch (Exception)
            {
                textBox1.Text = "C:\\" + Logic.Install.DisplayName;
                MessageBox.Show("路径不合法");
                return;
            }
            Logic.Install.InstallLocation =System.IO.Path.GetFullPath(textBox1.Text);
            Logic.MainForm.Next();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Logic.MainForm.Cancel();
        }

        private void SelectPath_Load(object sender, EventArgs e)
        {
            if (Logic.Install != null)
            {
                label1.Text = "欢迎使用" + Logic.Install.DisplayName + "安装工具";
                this.textBox1.Text = string.IsNullOrEmpty(Logic.Install.InstallLocation) ?
                    "C:\\" + Logic.Install.DisplayName : Logic.Install.InstallLocation;
            }
        }
    }
}
